From e3abab74598d96de87e3cbcaf1d567ac854e53cf Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 1 Dec 2014 11:31:12 +0000 Subject: [PATCH] libxl: un-constify return value of libxl_basename The string returned is malloc'ed but marked as "const". Signed-off-by: Wei Liu Cc: Ian Campbell Cc: Ian Jackson Acked-by: Ian Campbell --- tools/libxl/libxl.h | 10 ++++++++++ tools/libxl/libxl_utils.c | 5 ++++- tools/libxl/libxl_utils.h | 6 +++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 41d6e8db6c..291c1909f9 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -477,6 +477,16 @@ typedef struct libxl__ctx libxl_ctx; #define LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG 1 #endif +/* + * LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE + * + * The return value of libxl_basename is malloc'ed but the erroneously + * marked as "const" in releases before 4.5. + */ +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040500 +#define LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE 1 +#endif + /* * LIBXL_HAVE_PHYSINFO_OUTSTANDING_PAGES * diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 3e1ba170bd..22119fcb8a 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -19,7 +19,10 @@ #include "libxl_internal.h" -const char *libxl_basename(const char *name) +#ifdef LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE +const +#endif +char *libxl_basename(const char *name) { const char *filename; if (name == NULL) diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 117b22924c..8277eb9ec9 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -18,7 +18,11 @@ #include "libxl.h" -const char *libxl_basename(const char *name); /* returns string from strdup */ +#ifdef LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE +const +#endif +char *libxl_basename(const char *name); /* returns string from strdup */ + unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus); int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid); int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid); -- 2.30.2